package edu.unc.comp410.colemangeer.model.constraints;

import org.apache.log4j.Logger;


/**
 * A named constraint on the values allowed in a single data field.
 */
public abstract class Constraint implements IConstraint {
	
	// Data members
	private String name;
	private static Logger log = Logger.getLogger( Constraint.class );
		
	protected Constraint( final String theName ) {
		name = theName;
	}

	public String getConstraintName() {
		return name;
	}
	
	public abstract boolean isLegal( Object obj );
	
	public void validate( Object obj ) throws IllegalStateException {
		log.debug( "validate for " + getConstraintName() );
		if( ! isLegal( obj )) {
			log.debug( "!!! FAILS ");
			throw new IllegalStateException();
		}
	}

	
}
